// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  var id=event.id
  var topicID=event.topicID
  var type=event.type
  if(type==true){
    await db.collection('topic').doc(id).remove()
    return await db.collection('reply').where({
      topicID:id
    }).remove()
  }
  else{
    await db.collection('reply').doc(id).remove()
    
    return await db.collection('topic').doc(topicID).update({
      data:{
         topicReplyCount:_.inc(-1)
      }  
        })
  
    }
  
  }


